import { getPhoneLogin } from '@/request/api/home'
import { getMusicLyric } from '@/request/api/item'
import { createStore } from 'vuex'
// import { getMusicLyric } from '@/request/api/item'
export default createStore({
  state: {
    playList: [{
      al: {
        id: 128666473,
        name: "忘不掉的你",
        pic: 109951166071009310,
        picUrl: "https://p1.music.126.net/4BCskpY6Rmm-QReHnY8W6Q==/109951166071009318.jpg",
        pic_str: "109951166071009318"
      },
      id: 1851652156,
      ar: [{
        name: 'h3R3'
      }]
    }],
    playListIndex: 0,
    isbtnShow: true,
    detailShow: false,//歌曲详情页展示,
    lyricList: {},
    currentTime: 0,
    duration: 0,
    isLogin: false,
    isFooterMusic: true,
    token: '',
    user: {}
  },
  getters: {
  },
  mutations: {
    updateIsbtnShow: function (state, value) {
      state.isbtnShow = value
    },
    updatePlayList: function (state, value) {
      state.playList = value
      // console.log(state.playList);
    },
    updatePlayListIndex: function (state, value) {
      state.playListIndex = value
    },
    updateDetailShow: function (state) {
      state.detailShow = !state.detailShow
    },
    updateLyric: function (state, value) {
      state.lyricList = value
    },
    updateCurrentTime: function (state, value) {
      state.currentTime = value
      console.log(state.currentTime);
    },
    updateDuration: function (state, value) {
      state.duration = value
    },
    updateIsLogin: function (state, value) {
      state.isLogin = value
    },
    updateToken: function (state, value) {
      state.token = value
      localStorage.setItem('token', state.token)
    },
    updateUser:function(state,value){
      state.user=value
    }
  },
  actions: {
    getLyric: async function (context, value) {
      let res = await getMusicLyric(value)
      console.log(res);
      context.commit("updateLyric", res.data.lrc)

    },
    getLogin: async function (context, value) {
      let res = await getPhoneLogin(value)
      // console.log(res);
      return res
    }
  },
  modules: {
  }
})
